using System.Globalization;
using System.Text;
using Engine;
using Engine.Graphics;
using Game;

namespace SCIENEW {
    /// <summary>
    /// 矿石块
    /// </summary>
    public class OreChunkItem : MeshItem, IMaterialBlock {

        protected readonly BlockMesh m_standaloneBlockMesh = new BlockMesh();

        protected Materials material;

        public Materials GetMaterial() => material;

        public OreChunkItem(string id, Matrix transform, Matrix tcTransform, Color color, bool smooth) : base(id) {
            material = Materials.None;
            Color = color;
            var model = ContentManager.Get<Model>(smooth ? "Models/ChunkSmooth" : "Models/Chunk");
            m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone) * transform, false, false, false, false, color);
            m_standaloneBlockMesh.TransformTextureCoordinates(tcTransform);
        }

        public OreChunkItem(Matrix transform, Matrix tcTransform, Color color, bool smooth, Materials type) : base(type + "OreChunk") {
            string name = type.ToDisplayName();
            material = type;
            DisplayName = string.Format(LanguageControl.Get("Items", "Names", "OreChunkItem"), material.ToDisplayName());
            Description = string.Format(LanguageControl.Get("Items", "Descriptions", "OreChunkItem"), material.ToDisplayName());
            Color = color;
            var model = ContentManager.Get<Model>(smooth ? "Models/ChunkSmooth" : "Models/Chunk");
            m_standaloneBlockMesh.AppendModelMeshPart(model.Meshes[0].MeshParts[0], BlockMesh.GetBoneAbsoluteTransform(model.Meshes[0].ParentBone) * transform, false, false, false, false, color);
            m_standaloneBlockMesh.TransformTextureCoordinates(tcTransform);
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, IndustrialModLoader.IETexture, Color * color, 2f * size, ref matrix, environmentData);
        }

        public override string GetCraftingId() => Id;

        public override string GetCategory(int value) => "Terrain";

        public override float GetProjectilePower(int value) => 2f;

        public override float GetIconViewScale(int value, DrawBlockEnvironmentData environmentData) => 1;
    }
}